<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<%@ page language="java" import="java.sql.*" %>
<%@ page contentType="text/html; charset=UTF-8"%>
<%	String driver = "org.h2.Driver";
	Class.forName(driver).newInstance();
	
	Connection con=null;
	ResultSet rst=null;
	Statement stmt=null;
	
	try{
		
		con=DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
		stmt=con.createStatement();
	}
	catch(Exception e){
		System.out.println(e.getMessage());
	}
	if(request.getParameter("action") != null){ 
		String imie=request.getParameter("imie");
		String nazwisko=request.getParameter("nazwisko");
		String pseudonim=request.getParameter("pseudonim");
		String email=request.getParameter("email");
		String gatunek=request.getParameter("gatunek");
		stmt.executeUpdate("insert into dj(imie,nazwisko,pseudonim,email,gatunek) values('"+imie+"','"+nazwisko+"','"+pseudonim+"','"+email+"','"+gatunek+"')");
		rst=stmt.executeQuery("select * from dj");
		%>
		
		
		<html>
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="HEAD.txt"></jsp:include>
		</head>
		<body>
<jsp:include page="A.txt"></jsp:include>		
		<center>
			<h2>Dj's' List</h2>
			<table border="1" cellspacing="0" cellpadding="0">
			<tr>
				<td><b>ID</b></td>
				<td><b>Imię</b></td>
				<td><b>Nazwisko</b></td>
				<td><b>Pseudonim</b></td>
				<td><b>Email</b></td>
				<td><b>Gatunek</b></td>
			</tr>
			 	<%
				int no=1;
				while(rst.next()){
				%>
				<tr>
				  <td><%=no%></td>
				  <td><%=rst.getString("imie")%></td>
				  <td><%=rst.getString("nazwisko")%></td>
				  <td><%=rst.getString("pseudonim")%></td>
				  <td> <%=rst.getString("email")%> </td>
				  <td><%=rst.getString("gatunek")%></td>
				</tr>
				<%
				no++;
	}
	rst.close();
	stmt.close();
	con.close();
%>
			</table>
			<a href=index.jsp>Powrot</a>
			</center>
			<jsp:include page="Z.txt"></jsp:include>
		</body>
	</html>
<%}else{%>
	<html>
	<head>
		<title>Dj's ADD form</title>
		<script src="gen_validatorv4.js" type="text/javascript"></script>
		<jsp:include page="HEAD.txt"></jsp:include>		
		
		</head>
		
		<body>
		<jsp:include page="A.txt"></jsp:include>
			<center>
<form accept-charset="UTF-8" action="djAdd.jsp" method="post" name="entry" id="entry" onSubmit="return validate(this)">
	<input type="hidden" value="list" name="action">
	<table border="1" cellpadding="0" cellspacing="0">
	<tr>
		<td>
			<table>
				<tr>
				<td colspan="2" align="center">
<h2>Dj add</h2></td>
				</tr>
				<tr>
				<td colspan="2">&nbsp;</td>
				</tr>
				<tr>
				<td>Imię:</td>
				<td><input name="imie" type="text" size="50"></td>
				</tr>
				<tr>
				<td>Nazwisko:</td><td><input name="nazwisko" type="text" size="50"></td>
				</tr>
				<tr>
				<td>Pseudonim:</td><td><input name="pseudonim" type="text" size="50"></td>
				</tr>
				<tr>
				<td>Email:</td><td><input name="email" type="text" size="50"></td>
				</tr>
				<tr>
				<td>Gatunek:</td><td><input name="gatunek" type="text" size="50"></td>
				</tr>
				<tr>
					<td colspan="2" align="center">
<input type="submit" value="Submit"></td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
<script type="text/javascript">
var frmvalidator  = new Validator("entry");
frmvalidator.addValidation("imie","req","Wprowadz poprawne imię");
//frmvalidator.addValidation("imie","alpha","Wprowadz poprawne imie");
frmvalidator.addValidation("email","maxlen=50");
frmvalidator.addValidation("email","req","Pole email jest wymagane");
frmvalidator.addValidation("email","email","Blad w polu email");
frmvalidator.addValidation("nazwisko","req","Wprowadz poprawne nazwisko");
//frmvalidator.addValidation("nazwisko","alpha","Wprowadz poprawne nazwisko");
frmvalidator.addValidation("pseudonim","req","Wprowadz poprawny pseudonim");



</script>
			</center>
			<jsp:include page="Z.txt"></jsp:include>
		</body>
	</html>
<%}%>